package ntd.util.frame.javacv.dahua;


import cn.hutool.core.util.StrUtil;

import cn.hutool.http.ContentType;
import cn.hutool.http.server.SimpleServer;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.StaticLog;
import com.dahuatech.hutool.http.Method;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.http.DefaultClient;

import com.dahuatech.icc.oauth.model.v202010.GeneralRequest;
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
import ntd.util.config.common.enums.protocol.EnumStreamUrlProtocol;
import ntd.util.frame.action.function.video.bo.ActionVideoInBo;
import ntd.util.frame.action.function.video.tool.ToolDaHua;

import java.util.HashMap;
import java.util.Map;


public class DaHuaTest {
    public static void main(String[] args) throws ClientException {
        // 监听10860 端口
        SimpleServer simpleServer = new SimpleServer(10862);

        /*
            设备code：1006567
         */
        simpleServer.addAction("/get-dahua-video-url", (request, response) -> {

            String deviceCode = request.getParam("cameraIndexCode");

            if (StrUtil.isEmpty(deviceCode)) return;

            ActionVideoInBo actionVideoInBo = new ActionVideoInBo();
            actionVideoInBo.setDeviceCode(deviceCode);
            actionVideoInBo.setStreamUrlProtocol(EnumStreamUrlProtocol.PROTOCOL_RTSP);

            String url = ToolDaHua.me("192.168.3.118", "system", "hmshxxb159",
                    "fuminghuanbao-dahua", "a2520d3b-fabf-4db4-89ab-2a36fb106fff").getDeviceFirstUrl(actionVideoInBo);

            response.write(StrUtil.format("{\"data\":{\"url\":\"%s\"}}", url), ContentType.JSON.toString());

        }).start();


    }
}
